package com.mocha.util;

import java.util.Collection;
import java.util.Map;

public class AssertUtil {

    public static void notEmpty(Object o, RuntimeException exception) {
        if (o == null) {
            throw exception;
        } else if (o instanceof String) {
            if (EmptyUtil.isEmpty((String)o)) {
                throw exception;
            }
        } else if (o instanceof Collection) {
            if (EmptyUtil.isEmpty((Collection)o)) {
                throw exception;
            }
        } else if (o instanceof Map) {
            if (EmptyUtil.isEmpty((Map)o)) {
                throw exception;
            }
        } else if (o instanceof Object[]) {
            if (EmptyUtil.isEmpty((Object[])((Object[])o))) {
                throw exception;
            }
        }
    }

    public static void notEmpty(Object o, String message, Object... args) {
        if (o == null) {
            message = StringUtil.format(message, args);
            throw new IllegalArgumentException(message);
        } else if (o instanceof String) {
            if (EmptyUtil.isEmpty((String)o)) {
                message = StringUtil.format(message, args);
                throw new IllegalArgumentException(message);
            }
        } else if (o instanceof Collection) {
            if (EmptyUtil.isEmpty((Collection)o)) {
                message = StringUtil.format(message, args);
                throw new IllegalArgumentException(message);
            }
        } else if (o instanceof Map) {
            if (EmptyUtil.isEmpty((Map)o)) {
                message = StringUtil.format(message, args);
                throw new IllegalArgumentException(message);
            }
        } else if (o instanceof Object[]) {
            if (EmptyUtil.isEmpty((Object[])((Object[])o))) {
                message = StringUtil.format(message, args);
                throw new IllegalArgumentException(message);
            }
        }
    }

    public static void isEmpty(Object o, String message, Object... args) {
        if (o != null) {
            if (o instanceof String) {
                if (!EmptyUtil.isEmpty((String)o)) {
                    message = StringUtil.format(message, args);
                    throw new IllegalArgumentException(message);
                }
            } else if (o instanceof Collection) {
                if (!EmptyUtil.isEmpty((Collection)o)) {
                    message = StringUtil.format(message, args);
                    throw new IllegalArgumentException(message);
                }
            } else if (o instanceof Map) {
                if (!EmptyUtil.isEmpty((Map)o)) {
                    message = StringUtil.format(message, args);
                    throw new IllegalArgumentException(message);
                }
            } else if (o instanceof Object[]) {
                if (!EmptyUtil.isEmpty((Object[])((Object[])o))) {
                    message = StringUtil.format(message, args);
                    throw new IllegalArgumentException(message);
                }
            } else {
                message = StringUtil.format(message, args);
                throw new IllegalArgumentException(message);
            }
        }
    }

    public static void isEmpty(Object o, RuntimeException exception) {
        if (o != null) {
            if (o instanceof String) {
                if (!EmptyUtil.isEmpty((String)o)) {
                    throw exception;
                }
            } else if (o instanceof Collection) {
                if (!EmptyUtil.isEmpty((Collection)o)) {
                    throw exception;
                }
            } else if (o instanceof Map) {
                if (!EmptyUtil.isEmpty((Map)o)) {
                    throw exception;
                }
            } else if (o instanceof Object[]) {
                if (!EmptyUtil.isEmpty((Object[])((Object[])o))) {
                    throw exception;
                }
            } else {
                throw exception;
            }
        }
    }

    public static void isTrue(boolean expression, RuntimeException exception) {
        if (!expression) {
            throw exception;
        }
    }

    public static void isTrue(boolean expression, String message, Object... args) {
        if (!expression) {
            message = StringUtil.format(message, args);
            throw new IllegalArgumentException(message);
        }
    }


}
